home *** CD-ROM | disk | FTP | other *** search
- VERSION 4.00
- Begin VB.Form frmMain
- BorderStyle = 3 'Fixed Dialog
- Caption = "UDP Echo Sample Application"
- ClientHeight = 5820
- ClientLeft = 4620
- ClientTop = 2565
- ClientWidth = 4545
- BeginProperty Font
- name = "Arial"
- charset = 0
- weight = 700
- size = 8.25
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- ForeColor = &H80000008&
- Height = 6225
- Icon = "EchoUDP.frx":0000
- Left = 4560
- LinkTopic = "Form1"
- MaxButton = 0 'False
- ScaleHeight = 5820
- ScaleWidth = 4545
- Top = 2220
- Width = 4665
- Begin VB.PictureBox Picture1
- BorderStyle = 0 'None
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 0
- weight = 700
- size = 8.25
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- Height = 1185
- Left = 105
- ScaleHeight = 1185
- ScaleWidth = 4425
- TabIndex = 3
- Top = 630
- Width = 4425
- Begin VB.OptionButton opServerAddress
- Caption = "Use Server Address"
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 0
- weight = 400
- size = 8.25
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- Height = 225
- Left = 2310
- TabIndex = 9
- Top = 855
- Width = 2115
- End
- Begin VB.OptionButton opServerName
- Caption = "Use Server Name"
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 0
- weight = 400
- size = 8.25
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- Height = 225
- Left = 210
- TabIndex = 8
- Top = 855
- Value = -1 'True
- Width = 1905
- End
- Begin VB.TextBox txServerAddress
- BackColor = &H00FFFFFF&
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 0
- weight = 400
- size = 8.25
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- Height = 285
- Left = 1575
- TabIndex = 7
- Top = 450
- Width = 2745
- End
- Begin VB.TextBox txServerName
- BackColor = &H00FFFFFF&
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 0
- weight = 400
- size = 8.25
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- Height = 285
- Left = 1575
- TabIndex = 6
- Top = 100
- Width = 2745
- End
- Begin VB.Label Label2
- Alignment = 1 'Right Justify
- Appearance = 0 'Flat
- BackColor = &H00C0C0C0&
- Caption = "Server Address :"
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 0
- weight = 400
- size = 8.25
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- ForeColor = &H80000008&
- Height = 225
- Left = 0
- TabIndex = 5
- Top = 450
- Width = 1485
- End
- Begin VB.Label Label1
- Alignment = 1 'Right Justify
- Appearance = 0 'Flat
- BackColor = &H00C0C0C0&
- Caption = "Server Name :"
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 0
- weight = 400
- size = 8.25
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- ForeColor = &H80000008&
- Height = 225
- Left = 0
- TabIndex = 4
- Top = 100
- Width = 1485
- End
- End
- Begin VB.TextBox txStatus
- BackColor = &H00C0C0C0&
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 0
- weight = 400
- size = 8.25
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- Height = 330
- Left = 105
- TabIndex = 14
- Top = 5355
- Width = 4320
- End
- Begin VB.CommandButton btnEcho
- Caption = "&Echo"
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 0
- weight = 400
- size = 8.25
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- Height = 330
- Left = 180
- TabIndex = 0
- Top = 3045
- Width = 1275
- End
- Begin VB.ListBox lbEcho
- BackColor = &H00C0C0C0&
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 0
- weight = 400
- size = 8.25
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- Height = 1590
- Left = 105
- TabIndex = 1
- Top = 3675
- Width = 4320
- End
- Begin VB.TextBox txData
- BackColor = &H00FFFFFF&
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 0
- weight = 400
- size = 8.25
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- Height = 750
- Left = 1575
- TabIndex = 13
- Text = "This is a sample of echo data."
- Top = 2625
- Width = 2850
- End
- Begin VB.OptionButton opServiceNumber
- Caption = "Use echo Port Number (7)"
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 0
- weight = 400
- size = 8.25
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- Height = 225
- Left = 315
- TabIndex = 11
- Top = 2300
- Value = -1 'True
- Width = 2535
- End
- Begin VB.OptionButton opServiceName
- Caption = "Use echo Service Name"
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 0
- weight = 400
- size = 8.25
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- Height = 225
- Left = 315
- TabIndex = 10
- Top = 2000
- Width = 2535
- End
- Begin dsSocketLib.DSSocket DSSocket1
- Height = 420
- Left = 3240
- TabIndex = 15
- Top = 1920
- Width = 420
- _version = 65536
- _extentx = 741
- _extenty = 741
- _stockprops = 64
- localport = 0
- remotehost = ""
- remoteport = 0
- servicename = ""
- remotedotaddr = ""
- datasize = 2048
- linger = -1 'True
- timeout = 10
- linemode = 0 'False
- eolchar = 10
- bindconnect = 0 'False
- sockettype = 1
- End
- Begin VB.Label Label4
- Appearance = 0 'Flat
- BackColor = &H00C0C0C0&
- Caption = "Echo from server :"
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 0
- weight = 400
- size = 8.25
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- ForeColor = &H80000008&
- Height = 225
- Left = 105
- TabIndex = 2
- Top = 3465
- Width = 1905
- End
- Begin VB.Label Label3
- Alignment = 1 'Right Justify
- Appearance = 0 'Flat
- BackColor = &H00C0C0C0&
- Caption = "Data to echo :"
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 0
- weight = 400
- size = 8.25
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- ForeColor = &H80000008&
- Height = 225
- Left = 105
- TabIndex = 12
- Top = 2625
- Width = 1380
- End
- Attribute VB_Name = "frmMain"
- Attribute VB_Creatable = False
- Attribute VB_Exposed = False
- Option Explicit
- ' Declare the constants used to set the Action property
- ' and check the State of the socket
- Const SOCK_ACTION_CLOSE = 1
- Const SOCK_ACTION_CONNECT = 2
- Const SOCK_ACTION_LISTEN = 3
- Const SOCK_STATE_CLOSED = 1
- Const SOCK_STATE_CONNECTED = 2
- Private Sub btnEcho_Click()
- ' Setup to handle errors as they occur
- On Error Resume Next
- ' set to UDP socket type
- DSSocket1.SocketType = 1
- ' If the user selected to use the ServerName, then
- ' set the properties accordingly. If RemoteDotAddr is
- ' blank, then the control will use the RemoteHost information
- ' to resolve an address.
- If (opServerName) Then
- DSSocket1.RemoteHost = txServerName.Text
- DSSocket1.RemoteDotAddr = ""
- Else
- DSSocket1.RemoteHost = ""
- DSSocket1.RemoteDotAddr = txServerAddress.Text
- End If
- ' If the user selected to use the ServiceName, then
- ' set the properties accordingly. If RemotePort property is
- ' zero, then the control will use the ServiceName information
- ' to resolve a port number for making the connection.
- If (opServiceName) Then
- DSSocket1.ServiceName = "echo" ' set service name to "echo"
- DSSocket1.RemotePort = 0
- Else
- DSSocket1.ServiceName = ""
- DSSocket1.RemotePort = 7 ' standard TCP port number for echo
- ' as defined in SERVICES file
- End If
- ' If the socket is not already connected, the do a Connect
- If (DSSocket1.State = SOCK_STATE_CLOSED) Then
-
- ' show the status information
- txStatus.Text = "Connecting to server..."
-
- ' issue the connect command
- DSSocket1.Connect
-
- ' if there were any errors establishing the connection
- ' then report them
- If (Err > 0) Then
- MsgBox "Error attempting connect to server." & Chr(13) & Format(Err) & " : " & Error
- txStatus.Text = Error & "..."
- Exit Sub
- End If
- Else
- DSSocket1.Send = txData.Text
-
- End If
- End Sub
- Private Sub dsSocket1_Connect()
- txStatus.Text = "Connected to server " + txServerName.Text + "..."
- End Sub
- Private Sub dsSocket1_Receive(ReceiveData As String)
- '
- ' Process data echoed back from server
- '
- On Error Resume Next
- ' Display the data in the listbox
- lbEcho.AddItem DSSocket1.RemoteDotAddr & ":" & ReceiveData
- ' Make the last item the current one
- lbEcho.ListIndex = lbEcho.ListCount - 1
- ' Close the connection. Normally this wouldn't be done
- ' until we are actually finished with the connection. We
- ' do it here for demonstration purposes
- DSSocket1.Close
- ' If there were any errors then report them. The Action property
- ' will return errors in the standard VB error variables
- If (Err > 0) Then
- MsgBox "Error disconnecting from server." & Chr(13) & Format(Err) & " : " & Error
- txStatus.Text = Error & "..."
- Exit Sub
- ' If no errors, just report the status
- Else
- txStatus.Text = "Disconnected from server " + txServerName.Text + "..."
- End If
- End Sub
- Private Sub dsSocket1_SendReady()
- ' now that the socket is connected, send the data string to be echoed back
- DSSocket1.Send = txData.Text
- ' clear the RemoteDotAddr so we can see it come back in the UDP transfer
- DSSocket1.RemoteDotAddr = ""
- ' if there were any errors establishing the connection
- ' then report them
- If (Err > 0) Then
- MsgBox "Error sending data to server." & Chr(13) & Format(Err) & " : " & Error
- txStatus.Text = Error & "..."
- ' else show the status
- Else
- txStatus.Text = Format(Len(txData.Text)) + " bytes sent to server..."
- End If
- End Sub
- Private Sub Form_Paint()
- '
- ' This is simply some pretty header code
- '
- ' Setup to do a shadowed text title and copyright notice.
- FontSize = 30
- FontItalic = True
- ForeColor = &H0
- CurrentX = 140
- CurrentY = -50
- Print "Echo"
- ForeColor = &HFF0000
- CurrentX = 110
- CurrentY = -80
- Print "Echo"
- FontSize = 12
- CurrentX = 1800
- CurrentY = 300
- Print Chr(169) & "Dolphin Systems Inc."
- End Sub
-